/* Last exercise of chapter 1 on tronixstuff */

// Initializations
int i, j; // loop variables
int pins[10] = {2,3,4,5,6,7,8,9,12,13};
float v2 = 0;
float voltage = 0;

void setup() {
   // Pin modes
   for (i = 0; i < 10; i++) {
      pinMode(i,OUTPUT);
   }
   Serial.begin(9600);
}

void loop() {
   voltage = analogRead(5);
   v2 = voltage * 10 / 1024;
   
   Serial.print("Voltage: ");
   Serial.println(v2, 2);
   Serial.println(voltage, 2);
   
   if (v2 >= 0 && v2 < 1) {
      for (i = 0; i <=0; i++) {
         digitalWrite(pins[i],HIGH);
      }
      delay(1000);
   }
   else if (v2 >= 1 && v2 < 2) {
      for (i = 0; i <=1; i++) {
         digitalWrite(pins[i],HIGH);
      }
      delay(1000);
   }
   else if (v2 >= 2 && v2 < 3) {
      for (i = 0; i <=2; i++) {
         digitalWrite(pins[i],HIGH);
      }
      delay(1000);
   }
   else if (v2 >= 3 && v2 < 4) {
      for (i = 0; i <=3; i++) {
         digitalWrite(pins[i],HIGH);
      }
      delay(1000);
   }
   else if (v2 >= 4 && v2 < 5) {
      for (i = 0; i <=4; i++) {
         digitalWrite(pins[i],HIGH);
      }
      delay(1000);
   }
   else if (v2 >= 5 && v2 < 6) {
      for (i = 0; i <=5; i++) {
         digitalWrite(pins[i],HIGH);
      }
      delay(1000);
   }
   else if (v2 >= 6 && v2 < 7) {
      for (i = 0; i <=6; i++) {
         digitalWrite(pins[i],HIGH);
      }
      delay(1000);
   }
   else if (v2 >= 7 && v2 < 8) {
      for (i = 0; i <=7; i++) {
         digitalWrite(pins[i],HIGH);
      }
      delay(1000);
   }
   else if (v2 >= 8 && v2 < 9) {
      for (i = 0; i <=8; i++) {
         digitalWrite(pins[i],HIGH);
      }
      delay(1000);
   }
   else if (v2 >= 9 && v2 <= 10) {
      for (i = 0; i <=9; i++) {
         digitalWrite(pins[i],HIGH);
      }
      delay(1000);
   }
   
   for (j = 0; j <= 9; j++) {
      digitalWrite(pins[j],LOW);
   }
}
